package org.icress.fusion.moc

import org.icress.fusion.shiro.User
import org.apache.shiro.SecurityUtils
import org.springframework.transaction.annotation.*


class TaService {

    static transactional = true

    @Transactional(readOnly = true)
    def list(Object params) {
        def taInstanceList = Ta.list(params)
        return taInstanceList
    }
    
    @Transactional(readOnly = true)
    def count(Object params) {
        def taInstanceTotal = Ta.count()
        return taInstanceTotal
    }
    
    def save(Ta taInstance, Object params, boolean flush) {
        //get user
        def currentUser = User.findByUsername( SecurityUtils.getSubject().getPrincipal() )
        
        taInstance.createdBy = currentUser
        taInstance.lastModifiedBy = currentUser
        taInstance.owner = currentUser
        
        def success = taInstance.save(flush: flush)
        return success
    }
    
    def update(Ta taInstance, Object params, boolean flush) {
        //get user
        def currentUser = User.findByUsername( SecurityUtils.getSubject().getPrincipal() )
        
        taInstance.lastModifiedBy = currentUser
        
        def success = taInstance.save(flush: flush)
        return success
    }

    def get(Object id) {
        def taInstance = Ta.get(id)
        return taInstance
    }
    
    def delete(Ta taInstance, boolean flush) {
        def success = taInstance.delete(flush: flush)
        return success
    }
}